package com.vinoxm.admin.config.client;

import lombok.AllArgsConstructor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.oauth2.provider.ClientDetailsService;
import org.springframework.security.oauth2.provider.client.JdbcClientDetailsService;

import javax.sql.DataSource;

@Configuration
@AllArgsConstructor
public class ClientConfig {

    private DataSource dataSource;
    private PasswordEncoder passwordEncoder;

    @Bean
    // 管理 client信息
    // 相关表: oauth_client_details
    public ClientDetailsService jdbcClientDetailsService() {
        JdbcClientDetailsService service = new JdbcClientDetailsService(dataSource);
        service.setPasswordEncoder(passwordEncoder);
        return service;
    }
}
